<style>
	/*//混合类和抵押类公用该页面*/
    .liuzhuanEdit tr td input[type='text'] {
        cursor: auto ;
    }
    
    .diYaliuZhuanEdit table tr td:nth-child(1) {
	    width: 0.5%;
	}
	.diYaliuZhuanEdit tr td:last-child {
	    width: 11%;
	}
	.diYaliuZhuanEdit tr td input[type='text'] {
	    width: 100%;
	}
	.diYaliuZhuanEdit  .tableTop {
		height: 40px;
	}
	
</style>
<div class="container containerShadow">
        <div class="row">
            <div class="topimg">
                <div class="left pull-left">
                    <span>流转、前期处置及维护情况</span>
                </div>
            </div>

            <!--模态框开始（Modal）-->
            <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="false" >
                <div class="modal-dialog">
                    <div class="modal-content">
                        <div class="modal-header clearfix">
                            <div class="pull-left">
                                <img class="pull-left" src="image/projectDetails/"/>
                                <span class="pull-left uploadText"> 删除选项</span>
                            </div>
                            <img class="pull-right uploadImg" data-dismiss="modal" aria-hidden="true" src="/image/projectDetails/clos.png" title="单击关闭遮罩层" style="margin-top: 10px; cursor: pointer;">

                        </div>
                        <div class="modal-body">
                            <p>你确定删除选中内容吗?</p>
                        </div>
                        <div class="modal-footer">
                            <div class="cancelInConfirm cancelInConfirmMOdl">
                                <input id='cance' class="cancelInConfirmActive" type="button" value="确定" data-dismiss="modal"/>
                                <input id="confirm" class="active" type="button" value="取消" data-dismiss="modal"  />
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <!--模态框结束-->
            <form action="" method="" class="borderColor">
                <table class="liuzhuanEdit liuZh editTable liuZhEdit liuZhEditBox" border="" cellspacing="" cellpadding="">
                    <tr class="tableTop">
                        <th>
                            <input type="checkbox" class="whole" />
                        </th>
                        <th>转让日期</th>
                        <th>转让方-受让方</th>
                        <th>转让内容</th>
                        <th>备注</th>
                        <th>&nbsp;</th>
                    </tr>
                    <?php
                    if (!empty($transferHistory) && count($transferHistory) > 0) {
                        foreach ($transferHistory as $k => $v){
                            $transferDate = !empty($v['transfer_date'])?$v['transfer_date']:'';
                            $transfer = !empty($v['transfer'])?$v['transfer']:'';
                            $content = !empty($v['content'])?$v['content']:'';
                            $remark = !empty($v['remark'])?$v['remark']:'';
                            $historyId = !empty($v['id'])?$v['id']:'';
                            echo <<<TABLE
                                <tr>
                        <td>
                            <input type="checkbox" class='liuCheckbox' name="" id="" value="" />
                        </td>
                        <td>
                            <input type="text"  value="$transferDate" />
                        </td>
                        <td>
                            <input type="text"  value="$transfer" placeholder="如：信达—中信" />
                        </td>
                        <td>
                            <input type="text"  value="$content" />
                        </td>
                        <td>
                            <input type="text"  value="$remark" />
                        </td>
                        <td style="display:none">
                            <input type="text" hidde id="historyId" value="$historyId" />
                        </td>
                        <td style="display:none">
                            <input type="text" hidde  value="" />
                        </td>
                        <td>
                            <input type="button" class="addLi" value="添加" />
                            <input type="button" class='remove' onclick="removeData1(this)" value="删除" data-toggle="modal"/>
                        </td>
                    </tr>
TABLE;
                        }
                    }else{
                        echo <<<TABLE1
                <tr>
								<td>
									<input type="checkbox" class='liuCheckbox' name=" " id=" " value="" />
								</td>
								<td>
									<input type="text"  value="" />
								</td>
								<td>
									<input type="text"  placeholder="如：信达—中信" value="" />
								</td>
								<td>
									<input type="text"  value="" />
								</td>
								<td>
									<input type="text"  value="" />
								</td>
								<td>
									<input type="button" class="addLi" value="添加" />
								    <input type="button" onclick="removeData1(this)" value="删除" data-toggle="modal"/>
								</td>
							</tr>
TABLE1;
                    }
                    ?>
                </table>
                <!--<p>
                    按照转让日期先后顺序填写
                </p>-->
                <div class="cancelInConfirm top30">
                    <input id="ajaxHistory" class="cancelInConfirmActive" type="button" value="保存" />
                    <input id='cancelHistory' type="button" value="取消" />
                </div>

            </form>
        </div>
    </div>
</div>
<script>
    //删除记录
    function removeData1(obj) {
        layer.confirm('确定删除？', {
            btn: ['确定', '取消'] //按钮
        }, function () {
            historyId = $(obj).parent().parent().find('td').eq(5).find('input').val();
            historyObj = $(obj).parent().parent().find('td').eq(5).find('input').parent().parent();
            if(historyId!=0 || historyId!=''){
                delData(historyId,historyObj)
            }else{
                layer.msg("删除成功");
                $(historyObj).remove();
            }
        }, function () {
//                $("#cancel").trigger('click')
        });
    }
    function delData(historyId,obj) {
        $.post('/project/ajax-del-transger-history-project', {'id': historyId, 'project_id': project_id}, function (res) {
            if (res) {
                layer.msg("删除成功");
                $(historyObj).remove();
            } else {
                layer.msg("删除失败");
            }
        })
    }

	$(function(){
        var transfer_date = ''; //转让日期
        var transfer = ''; //转让/处置方
        var content = ''; //转让/处置内容
        var remark = '';   //备注
        var order = ''; //序号
        var historyId = '';
        var dataArr = {};

        //ajax 保存数据
        $('#ajaxHistory').click( function () {
            $('.liuzhuanEdit').find('tr').each(function(i,v){
                var data = {};
                if(i>0){
                    var tdArr = $(this).children();
                    data['project_id'] = project_id;
                     data['transfer_date'] = tdArr.eq(1).find('input').val();//转让日期
                     data['transfer'] = tdArr.eq(2).find('input').val();//转让/处置方
                     data['content'] = tdArr.eq(3).find('input').val();//    转让/处置内容
                    data['remark'] = tdArr.eq(4).find('input').val();//    备注
                    data['order'] = parseInt(0);//    序号
                    data['historyId'] = tdArr.eq(5).find('input').val();//    id
                    dataArr[i] = data;
                }
            });
            $.post('/project/ajax-save-transger-history-project',{'data':dataArr,'project_id':project_id},function (res) {
                var JSONData = JSON.parse(res)
                if (JSONData.code == 200){
                    layer.msg(JSONData.message);
                    mainW();
                    location.reload();
                }else{
                    layer.msg(JSONData.message);
                }
            })
        })
        //-----------------渲染无编辑页面--------------------
        function mainW() {
            $.get('/project/get-base-data',{'project_id':project_id,'postion':12},function (res) {
                $(".liuZhuanJiWieHuW").children().remove();
                $(".liuZhuanJiWieHuW").html(res);
                $(".liuZhuanJiWieHuEdit").hide();
                $(".liuZhuanJiWieHuW").show();
            })
        }
        //-----取消保存按钮
        $("#cancelHistory").click(function () {
            $.post('/project/ajax-un-lock',{'postion':12,'project_id':project_id},function (res) {
                var JSONData = JSON.parse(res)
                if (JSONData.code == 200){
                    layer.msg(JSONData.message);
                }else{
                    layer.msg(JSONData.message);
                }
            })
            $(".liuZhuanJiWieHuEdit").hide();
            $(".liuZhuanJiWieHuW").show();
        })
    })
    //高亮显示开始
    $(".borderColor").on("focus",'input',function(){
				$(this).css({
							'border':'1px solid #2194f1'
				})
			})
	$(".borderColor").on("blur",'input',function(){
		$(this).css({
					'border':'1px solid #e2e2e2'
		})
	})
     //高亮显示结束
</script>